﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace e3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }



        private void File1Btn_Click(object sender, EventArgs e)
        {
            OpenFileDialog openfile = new OpenFileDialog();
            string filename;
            openfile.InitialDirectory = "./";
            openfile.Title = "请选择文件夹";
            openfile.Filter = "文本文件(*.txt)|*.txt";
            if (openfile.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = System.IO.Path.GetFullPath(openfile.FileName);//将选中的文件的路径传递给TextBox “FilePath”
            }
        }

        private void File2Btn_Click(object sender, EventArgs e)
        {
            OpenFileDialog openfile = new OpenFileDialog();
            string filename;
            openfile.InitialDirectory = "./";
            openfile.Title = "请选择文件夹";
            openfile.Filter = "文本文件(*.txt)|*.txt";
            if (openfile.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = System.IO.Path.GetFullPath(openfile.FileName);//将选中的文件的路径传递给TextBox “FilePath”
            }
        }

        private void FileMix_Click(object sender, EventArgs e)
        {
            string file1 = textBox1.Text;
            string file2 = textBox2.Text;
            string file3 = "3.txt";
            string content = "";

            using (FileStream fs3 = new FileStream(file3, FileMode.Create, FileAccess.Write))
            {
                using (StreamWriter sr3 = new StreamWriter(fs3, Encoding.Default))
                {
                    using (FileStream fs1 = new FileStream(file1, FileMode.Open, FileAccess.Read))
                    {
                        using (StreamReader sr1 = new StreamReader(fs1, Encoding.Default))
                        {
                            int lineNum = 0;
                            while ((content = sr1.ReadLine()) != null)
                            {
                                lineNum++;
                                sr3.WriteLine(file2 + "|" + lineNum + ":\t" + content);
                            }
                        }
                    }
                    using (FileStream fs2 = new FileStream(file2, FileMode.Open, FileAccess.Read))
                    {
                        using (StreamReader sr2 = new StreamReader(fs2, Encoding.Default))
                        {
                            int lineNum = 0;
                            while ((content = sr2.ReadLine()) != null)
                            {
                                lineNum++;
                                sr3.WriteLine(file2 + "|" + lineNum + ":\t" + content);
                            }
                        }
                    }
                }
            }
        }
    }
}
